package abq2.jic.jic.plugin.operate.activity;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.list.IListView;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;

/**
 * 标准单据列表插件
 */
public class GiveUp extends AbstractListPlugin implements Plugin {
    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs e) {
        super.beforeDoOperation(e);
        String operateKey = ((FormOperate) e.getSource()).getOperateKey();
        if (operateKey.equals("giveup")){
            IListView list = (IListView) this.getView();
            ListSelectedRow currentSelectedRowInfo = list.getCurrentSelectedRowInfo();
            Object primaryKeyValue = currentSelectedRowInfo.getPrimaryKeyValue();

            DynamicObject myActivity = BusinessDataServiceHelper.loadSingle("abq2_my_activity",
                    "creator,id," +
                            "number,abq2_activity",
                    new QFilter[]{new QFilter("id",QCP.equals, primaryKeyValue)});

            long activityId = myActivity.getLong("abq2_activity.id");

            QFilter idFilter = new QFilter("id", QCP.equals,activityId);
            DynamicObject activity = BusinessDataServiceHelper.loadSingle("abq2_activity",
                    "id," + //内码
                            "name," + //活动名称
                            "abq2_admin," + //活动管理员
                            "abq2_telephone," + //管理员手机号码
                            "abq2_time_end1," + //报名结束时间
                            "abq2_timebegin2," + //活动时间开始
                            "abq2_time_end2," + //活动时间结束
                            "abq2_place," + //活动地点
                            "abq2_method," + //考勤方式
                            "abq2_type," +  //活动类型
                            "abq2_limit," + //限报人数
                            "abq2_introduce," + //活动介绍
                            "abq2_integerfield," + //活动分
                            "abq2_integerfield1",  //已报人数
                    new QFilter[]{idFilter});
            int activityIntInt = activity.getInt("abq2_integerfield1");
            activity.set("abq2_integerfield1", activityIntInt - 1);
            SaveServiceHelper.update(activity);


            DeleteServiceHelper.delete("abq2_my_activity",new QFilter[]{new QFilter("id", QCP.equals,primaryKeyValue)});
            list.refreshWithSelected();
            this.getView().showSuccessNotification("退选成功");

            Double d = 11.00;
            int i = d.intValue();
        }
    }
}